home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: RAND_MAX
- Date: Mon, 01 Apr 96 14:56:10 GMT
- Organization: none
- Message-ID: <828370570snz@genesis.demon.co.uk>
- References: <4jnr55$e6l@skivs.ski.org>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4jnr55$e6l@skivs.ski.org> gt@ns.oon.or.jp "Gemini Thunder" writes:
-
- >I have a (stupid) question / observation about RAND_MAX.
- >
- >K&R2 says:
- > "rand returns a a pseudo-random integer in the range 0 to RAND_MAX,
- >which is at least 32767"
- >
- >It looks like RAND_MAX is not required to be the same as any other
- >limit (such as MAX_INT, etc.), that is fine, but why?
- >Wouldn't it be easier if RAND_MAX == MAX_INT or some other value?
-
- RAND_MAX is a characteristic of the algorithm used, not simply the types
- supported by the implementation.
- >
- >The reason I say this is how can you be sure your array will hold a
- >RAND_MAX sized integer, without some checking before hand, if RAND_MAX
- >is out there doing its own thing?
-
- rand() returns int so you can hold the value in an int and RAND_MAX can't be
- greater than INT_MAX. However it is guaranteed to be at least 32767.
-
- >Or does ANSI pin it down (in which case why have a RAND_MAX #defined),
- >or am I just worked up over nothing and overlooking something obvious?
-
- Store it in an int.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-